package eteam.aps.controller;

import eteam.aps.common.R;
import eteam.aps.common.exceptions.BusinessException;
import eteam.aps.common.helper.Helper;
import eteam.aps.common.helper.JsonPage;
import eteam.aps.model.dto.ScanProAlreadyDto;
import eteam.aps.model.dto.ScanProDto;
import eteam.aps.model.dto.ScanProWithoutDto;
import eteam.aps.model.vo.scan.ScanProAlreadyVo;
import eteam.aps.model.vo.scan.ScanProWithoutVo;
import eteam.aps.service.ProcessPreserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 产品工序维护
 *
 * @author LiuLei
 */
@Api(tags = "产品维护")
@RestController
@RequestMapping("/pcpc")
public class ProcessPreserveController {

    @Autowired
    private ProcessPreserveService processPreserveService;

    @PostMapping("sal")
    @ApiOperation("查询已扫描数据信息")
    @ApiImplicitParam(name = "ScanProAlreadyDto", value = "查询条件")
    public R<JsonPage<ScanProAlreadyVo>> selAlreadyLis(@RequestBody ScanProAlreadyDto dto) {
        // 将空字符串 填充为null
        Helper.setEmptyWithNull(dto);
        return R.success(processPreserveService.selAlreadyLis(dto));
    }

    @PostMapping("swl")
    @ApiOperation("查询未扫描数据信息")
    @ApiImplicitParam(name = "ScanProAlreadyDto", value = "查询条件")
    public R<JsonPage<ScanProWithoutVo>> selWithoutLis(@RequestBody ScanProWithoutDto dto) {
        // 将空字符串 填充为null
        Helper.setEmptyWithNull(dto);
        return R.success(processPreserveService.selWithoutLis(dto));
    }

    @PostMapping("da")
    @ApiOperation("删除已扫描信息")
    @ApiImplicitParam(name = "ScanProDto", value = "已扫描信息")
    public R<Integer> delAlready(@RequestBody ScanProDto dto) throws Exception {
        if (Helper.isEmpty(dto.getfId())) throw new BusinessException(HttpStatus.BAD_REQUEST, "内码不能为空！");
        if (Helper.isEmpty(dto.getfBarCode())) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品条码不能为空！");
        if (Helper.isEmpty(dto.getfInvCode())) throw new BusinessException(HttpStatus.BAD_REQUEST, "物料编码不能为空！");
        if (Helper.isEmpty(dto.getfScaPro())) throw new BusinessException(HttpStatus.BAD_REQUEST, "工序不能为空！");
        return R.success(processPreserveService.delAlready(dto));
    }

    @PostMapping("dw")
    @ApiOperation("删除未扫描信息")
    @ApiImplicitParam(name = "ScanProDto", value = "未扫描信息")
    public R<Integer> delWithout(@RequestBody ScanProDto dto) throws Exception {
        if (Helper.isEmpty(dto.getfId())) throw new BusinessException(HttpStatus.BAD_REQUEST, "内码不能为空！");
        if (Helper.isEmpty(dto.getfBarCode())) throw new BusinessException(HttpStatus.BAD_REQUEST, "产品条码不能为空！");
        if (Helper.isEmpty(dto.getfInvCode())) throw new BusinessException(HttpStatus.BAD_REQUEST, "物料编码不能为空！");
        if (Helper.isEmpty(dto.getfScaPro())) throw new BusinessException(HttpStatus.BAD_REQUEST, "工序不能为空！");
        return R.success(processPreserveService.delWithout(dto));
    }


}
